package com.dayu.web.controller;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dayu.web.param.TokenParam;
import com.dayu.web.vo.RESTResponse;

/**
 * 关于系统
 * 
 * @author Chenjiawei
 *
 *         2017年6月12日
 */
@Controller
@RequestMapping("/unitalk/v1.0")
public class SystemCtrl {

	static Logger LOGGER = LoggerFactory.getLogger(SystemCtrl.class);

	/**
	 * 系统重载
	 * 
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/reload.json", method = { RequestMethod.POST })
	public String reload(@RequestBody TokenParam token,
			HttpServletRequest request) {

		LOGGER.info("/reload.json");
		Runtime.getRuntime().addShutdownHook(new Thread() {
			public void run() {
				try {
					String restartCmd = "java -jar unitalk-app-1.0.1.jar";
					Runtime.getRuntime().exec(restartCmd);
				} catch (Exception e) {
				}
			}
		});

		try {
			Thread.sleep(1 * 1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

		System.exit(0);

		return RESTResponse.of(0, "重启成功！").toString();

	}

}
